package com.isoft.illustrationsdraw.service.impl;

import com.isoft.illustrationsdraw.entity.ReportStatusLog;
import com.isoft.illustrationsdraw.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService {
    
    @Autowired
    private JavaMailSender mailSender;

    @Override
    public boolean sendMagicLink(String toEmail, String magicLink) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(toEmail);
        message.setSubject("这是用于登录的魔法链接");
        message.setText("请点击这个魔法链接以登录网站：\n" + magicLink + "\n" + "如果您没有请求登录，请忽略这封邮件。");
        message.setFrom("your-email@example.com");

        mailSender.send(message);
        return true;
    }

    @Override
    public boolean sendReminderMessage(String toEmail, String name, String url) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(toEmail);
        message.setSubject("您有新的约稿请求");
        message.setText(String.format("昵称为（%s）的用户向您请求约稿，您可以前往 %s 与Ta讨论请求。", name, url));
        message.setFrom("your-email@example.com");
    
        mailSender.send(message);
        return true;
    }

    @Override
    public boolean sendReportUpdateRemindToReporter(String toEmail, ReportStatusLog reportLog) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setTo(toEmail);
        message.setSubject("报告状态更新提醒");
    
        // 构建邮件内容
        String text = String.format(
            "尊敬的用户，您好！\n\n" +
            "您的报告状态已更新：\n" +
            "- 报告ID：%d\n" +
            "- 新状态：%s\n" +
            "- 更新时间：%s\n" +
            "- 更新人：%d\n" +
            "- 备注：%s\n\n" +
            "感谢您的使用！",
            reportLog.getReportId(),
            reportLog.getStatus(),
            reportLog.getChangedAt(),
            reportLog.getChangedBy(),
            reportLog.getComment() != null ? reportLog.getComment() : "无"
        );
        message.setText(text);
        message.setFrom("your-email@example.com");
    
        // 发送邮件
        mailSender.send(message);
        return true;
    }
    
    
}
